package ${scheme.packageName}.controller.api;
import java.util.Date;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
import com.framework.loippi.utils.ParameterUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.framework.loippi.api.core.GenericAPIController;
import com.framework.loippi.api.utils.ApiUtils;

import ${scheme.packageName}.entity.${table.className};
import ${scheme.packageName}.service.${table.className}Service;
import com.framework.loippi.support.Message;
import com.framework.loippi.support.Pageable;
import com.framework.loippi.utils.ParameterUtils;
import com.framework.loippi.utils.StringUtil;
import java.util.HashMap;

/**
 * Controller - ${scheme.moduleName}
 * 
 * @author ${scheme.author!'Loippi Team'}
 * @version ${current_version}
 */
@Controller("${table.className}APIController")
@RequestMapping({ "/api/${classNamePath}" })
public class ${table.className}APIController extends GenericAPIController {

	@Resource
	private ${table.className}Service ${table.className?uncap_first}Service;

	

	/**
	 * 新增保存
	 */
	@RequestMapping(value = "/save", method = RequestMethod.POST)
	@ResponseBody
	public String save(${table.className} ${table.className?uncap_first}) {
		${table.className?uncap_first}Service.save(${table.className?uncap_first});
		return ApiUtils.success();
	}

	
	
	
	/**
	 * 详情
	 */
	@RequestMapping(value = "/view", method = RequestMethod.POST)
	@ResponseBody
	public String view(Long id) {
		${table.className} ${table.className?uncap_first} = ${table.className?uncap_first}Service.find(id);
		return ApiUtils.success(${table.className?uncap_first});
	}
	

	/**
	 * 更新
	 */
	@RequestMapping(value = "/update", method = RequestMethod.POST)
	@ResponseBody
	public String update(${table.className} ${table.className?uncap_first}) {
		${table.className?uncap_first}Service.update(${table.className?uncap_first});
		return ApiUtils.success();
	}

	/**
	 * 列表查询
	 * 
	 * @param pageable
	 * @param model
	 * @return
	 */
	@RequestMapping(value = { "/list" }, method = { RequestMethod.POST })
	@ResponseBody
	public String list(Integer pageNumber, Integer pageSize,HttpServletRequest request, ModelMap model) {
		Pageable pageable = new Pageable(pageNumber, pageSize);
		Map<String, Object> map=new HashMap();
		pageable.setParameter(map);
		Page<${table.className}> page = this.${table.className?uncap_first}Service.findByPage(pageable);
		return ApiUtils.success(page.getContent());
	}

	/**
	 * 删除操作
	 * 
	 * @param ids
	 * @return
	 */
	@RequestMapping(value = { "/delete" }, method = { RequestMethod.POST })
	public @ResponseBody Message delete(Long[] ids) {
		this.${table.className?uncap_first}Service.deleteAll(ids);
		return ApiUtils.success();
	}
}
